<?php
namespace app\admin\controller;
use think\Db;
use changpay\ChangPay;
use app\common\controller\order\Orderget;
class Renzhengbank extends Common
{
//	 银行卡解除绑定页面
	public function jiebang(){
		$ID= input('ID');
		$data=Db::table('xb_renzen_bank')->where('ID',$ID)->find();
		$this->assign('data',$data);
		return $this->fetch();
	}
	//	 银行卡解除绑定操作
	public function jiebang_caozuo(){
		$this->logs('银行卡解绑');
		$data= input();
//		p($data);die;
		$changpay= new \changpay\ChangPay;
		$data['Status']='2';
		$dataxiuga['isBank']='0';
		$data['UpdateTime']=date('Y-m-d H:i:s');//时间
		$re=Db::table('xb_renzen_bank')->update($data);
		$UserID=Db::table('xb_renzen_bank')->where(['ID'=>$data['ID']])->value('UserID');//获取UserID
		$res=Db::table('xb_mem_info')->where(['ID'=>$UserID])->update($dataxiuga);//修改用户表身份证认证状态
		$MerchantNo=Db::table('xb_sys_inteparameter')->where('ParaName','changpay')->value('ParaValue');
//		$MerchantNo = '200002080023' ; //商户号码
		$ressss=$changpay->jiebang($data['BankNo'],$UserID,$MerchantNo);
		if($ressss){
	    show_success();
		}else{
			show_error();
		}	
	}
	
//   认证列表页面
    public function index()
    {
		return $this->fetch();	
    }
//	 认证表页面数据
    public function get_list()
    {	
		$page = input('page');
		$limit = input('limit');
		$sorch=input('sorch');
		$sorch_aaa=input('sorch_aaa');
		$Orderget=New Orderget();
		$where1=$Orderget->sorch($sorch,$sorch_aaa);
		if(empty($where1)){
			$where=[];
		}
		if(!empty($where1['TrueName'])){
			$where['b.TrueName']=$where1['TrueName'];
		}
		if(!empty($where1['BankNo'])){
			$where['a.BankNo']=$where1['BankNo'];
		}
        $data=Db::table('xb_renzen_bank a')
        ->page($page,$limit)
        ->order('a.ID desc')
		->join('xb_mem_info b','a.UserID=b.ID','LEFT')
		->field('b.TrueName,b.TrueName2,a.Status,b.IDCard,a.RenzTime,a.ID,a.BankName,a.BankNo,a.UpdateTime,a.YMobile')
        ->where($where)
        ->select();
		$cuont=Db::table('xb_renzen_bank a')
        ->page($page,$limit)
        ->order('a.ID desc')
		->join('xb_mem_info b','a.UserID=b.ID','LEFT')
		->field('b.TrueName,b.TrueName2,a.Status,b.IDCard,a.RenzTime,a.ID')
        ->where($where)
        ->count('a.ID');
//		0待审核 1已认证 2认证失败
		foreach ($data as $k => $v) {
			if($v['Status']=='0'){
			$v['Status']='<span style="color:green;">待审核</span>';
			}
			if($v['Status']=='1'){
			$v['Status']='<span style="color:green;">已认证</span>';
			}
			if($v['Status']=='2'){
			$v['Status']='<span style="color:red;">认证失败</span>';
			}
			$data[$k]=$v;
		}
		
		songsong($data,$cuont);
    }
	//	银行卡认证编辑页面
	public function editss(){
		$ID= input('ID');
		$data=Db::table('xb_renzen_bank')->where('ID',$ID)->find();
		$this->assign('data',$data);
		return $this->fetch();
	}
	//	银行卡认证编辑操作
	public function edit(){
		$this->logs('银行卡认证编辑');
		$data= input();
		if(!empty($data['Status']) && $data['Status']=='on'){
			$data['Status']='1';
			$dataxiuga['isBank']='1';
		}else{
			$data['Status']='2';
			$dataxiuga['isBank']='0';
		}
		$data['UpdateTime']=date('Y-m-d H:i:s');//时间
		$re=Db::table('xb_renzen_bank')->update($data);
		$UserID=Db::table('xb_renzen_bank')->where(['ID'=>$data['ID']])->value('UserID');//获取UserID
		$res=Db::table('xb_mem_info')->where(['ID'=>$UserID])->update($dataxiuga);//修改用户表身份证认证状态
		if($re){
	    show_success();
		}else{
			show_error();
		}	
	}
}
